package com.example.rbac.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/7.
 */

//分页类
public class Page<T> {
    private int currentPageNum = 1;// 当前第几页(默认第一页),---主要用于传递到前台显示
    private int totalPageNum;// 总页数
    private int totalCount;// 总记录数
    private int perPageSize = 5;// 每页显示的记录条数(默认5条)

    private List<T> entitys;


    public Page(int currentPageNum, int totalCount, int perPageSize, List entitys, int totalPageNum) {
        this.totalCount = entitys != null && entitys.size()>0?entitys.size():0;
        this.perPageSize = perPageSize;
        this.entitys = entitys;
        this.totalPageNum = totalCount % perPageSize == 0 ? totalCount / perPageSize : totalCount / perPageSize + 1;
        this.currentPageNum = currentPageNum<1?1:(currentPageNum>totalPageNum?totalPageNum:currentPageNum);
    }

    // 使用默认的当前页和每页显示记录条数
    public Page(List entitys, int currentPageNum) {
        this.totalCount = entitys != null && entitys.size()>0?entitys.size():0;
        this.totalPageNum = totalCount % perPageSize == 0 ? totalCount
                / perPageSize : totalCount / perPageSize + 1;
        this.entitys = entitys;
        this.currentPageNum = currentPageNum<1?1:(currentPageNum>totalPageNum?totalPageNum:currentPageNum);//如果当前页小于第一页，则停留在第一页
    }

    public Page(Integer currentPageNum, Integer perPageSize, List<T> entitys, Integer totalCount) {
        this.totalCount = totalCount;
        this.totalPageNum = totalCount % perPageSize == 0 ? totalCount
                / perPageSize : totalCount / perPageSize + 1;
        this.entitys = entitys;
        if(currentPageNum != null){
            this.currentPageNum = currentPageNum<1?1:(currentPageNum>totalPageNum?totalPageNum:currentPageNum);//如果当前页小于第一页，则停留在第一页
        }
        this.perPageSize = perPageSize == null?this.perPageSize : perPageSize;
    }

    public Page() {
    }

    public int getCurrentPageNum() {
        return currentPageNum;
    }

    public void setCurrentPageNum(int currentPageNum) {
        this.currentPageNum = currentPageNum<1?1:(currentPageNum>totalPageNum?totalPageNum:currentPageNum);//如果当前页小于第一页，则停留在第一页
    }

    public int getTotalPageNum() {
        return totalPageNum;
    }

    public void setTotalPageNum(int totalPageNum) {
        this.totalPageNum = totalCount % perPageSize == 0 ? totalCount
                / perPageSize : totalCount / perPageSize + 1;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPerPageSize() {
        return perPageSize;
    }

    public void setPerPageSize(int perPageSize) {
        this.perPageSize = perPageSize;
    }

    public List getEntitys() {
        return entitys;
    }

    public void setEntitys(List entitys) {
        this.entitys = entitys;
    }
}
